/**
 *
 * <p>Title:PoolCreator  </p>
 * <p>Description： 线程池初始化工具类 </p>
 * Package: com.travelsky.aic.data.jobs.agentmonitor.util.task
 * Copyright: Copyright(c) 2020 Travelsky All Rights Reserved
 * Company: Travelsky
 * Software: AIC
 * Date: 2021/1/15 9:25
 *
 * @author yanwen
 * @version 1.0.0
 *
 */
package com.xiaoma.thread.pool;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author yanwen
 * 待持续优化，
 * 实现动态配置及可参数配置 等
 */
public  class PoolCreator {

  /**
   * 线程资源池对象
   */
  private static TaskResourcePool pool = null;
  /**
   * 是否超时设置
   */
  private final static boolean  threadTimeOut = false;
  /**
   * 核心线程池数量
   */
  private final static  int corePoolSize = 4;
  /**
   * 最大线程池数量
   */
  private final static  int maxPoolSize = 12;
  /**
   * 持续活跃时间10分钟
   */
  private final static  int keepAliveSeconds = 0;
  /**
   * 队列容量
   */
  private final static  int QueueCapacity = 20;

  /**
   * 初始化
   */
  static {
    pool = new TaskResourcePool();
    pool.setAllowCoreThreadTimeOut(threadTimeOut);
    pool.setCorePoolSize(corePoolSize);
    pool.setMaxPoolSize(maxPoolSize);
    pool.setKeepAliveSeconds(keepAliveSeconds);
    pool.setQueueCapacity(QueueCapacity);
    pool.initialize();
  }

  /**
   * 获取资源池执行器
   * @return
   */
  public static ThreadPoolExecutor getExecutor(){
    return pool.getThreadPoolExecutor();
  }

}
